package chpt10;
import javax.swing.JOptionPane;

public class JOptionPaneTest {
    public static void main(String[] args) {
        // 显示一个消息框
        JOptionPane.showMessageDialog(null, "显示一些消息");

        // 显示一个带标题和图标的消息框
        JOptionPane.showMessageDialog(null, "显示一些消息", "消息框", JOptionPane.INFORMATION_MESSAGE);

        // 显示一个确认框，获取用户的选择
        int result = JOptionPane.showConfirmDialog(null, "你确定？", "确认框", JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            System.out.println("点击了是");
        } else if (result == JOptionPane.NO_OPTION) {
            System.out.println("点击了否");
        } 

        // 显示一个输入框，获取用户的输入
        String input = JOptionPane.showInputDialog(null, "请输入你的答案:");
        if (input != null) {
            System.out.println("输入了: " + input);
        }
        
        Object[] options = { "A", "B", "C" };
        result = JOptionPane.showOptionDialog(null, "你要选择哪项:", "选项对话框", JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

        if (result == 0) {
            System.out.println("选择了A");
        } else if (result == 1) {
            System.out.println("选择了B");
        } else if (result == 2) {
            System.out.println("选择了C");
        }
    }
}